package ${packageName}.dao;

import org.springframework.jdbc.core.*;
import org.springframework.jdbc.core.namedparam.*;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcDaoSupport;

import ${packageName}.domain.*;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Generator by JdbcGenerator
 */
//@Repository
public class ${className}Dao extends NamedParameterJdbcDaoSupport{
     protected static String TABLE_NAME="${tableName}";
     protected static String PRIMARY_KEY="${pkColumn}";
     protected static final String COUNT_ALL = "select count(*) from "+TABLE_NAME;
     protected static final String INSERT_ALL = "${sql_insertAll}";
     protected static final String UPDATE_ALL = "${sql_updateAll}";
     public static RowMapper  mainRowMapper =new RowMapper (){
        @Override
        public ${className} mapRow(ResultSet resultSet, int i) throws SQLException {
            ${className} bean=new ${className}();
<%for (landyer.tools.jdbcGenerator.ColumnBean cb : cbs) {%>
            bean.${cb.getSetterName()}(resultSet.${cb.getResultSetGetterName()}("${cb.getName()}"));<%}%>
            return bean;
        }
    };
    //@Autowired
    //public ${className}Dao(DataSource dataSource){
        //setDataSource(dataSource);
    //}

    public void insert( ${className} bean){
        MapSqlParameterSource params = new MapSqlParameterSource();
<%for (landyer.tools.jdbcGenerator.ColumnBean cb : cbs) {%>
        params.addValue("${cb.getAdjustName()}",bean.${cb.getGetterName()}());<%}%>
        getNamedParameterJdbcTemplate().update(INSERT_ALL, params);
    }

}